package com.qulai.web.controller.basic;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.qulai.amazon_us.domain.vo.IfExistImageToSkuVo;
import com.qulai.amazon_us.domain.vo.ImageToSkuVo;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qulai.common.annotation.Log;
import com.qulai.common.core.controller.BaseController;
import com.qulai.common.core.domain.AjaxResult;
import com.qulai.common.enums.BusinessType;
import com.qulai.amazon_us.domain.basic.ImageToSku;
import com.qulai.amazon_us.service.basic.IImageToSkuService;
import com.qulai.common.utils.poi.ExcelUtil;
import com.qulai.common.core.page.TableDataInfo;

/**
 * 图片生成skuController
 * 
 * @author hunan
 * @date 2025-08-06
 */
@RestController
@RequestMapping("/basic/imageToSku")
public class ImageToSkuController extends BaseController
{
    @Autowired
    private IImageToSkuService imageToSkuService;

    /**
     * 查询图片生成sku列表
     */
    @PreAuthorize("@ss.hasPermi('basic:imageToSku:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImageToSku imageToSku)
    {
        startPage();
        List<ImageToSkuVo> list = imageToSkuService.selectImageToSkuVoList(imageToSku);
        return getDataTable(list);
    }

    /**
     * 导出图片生成sku列表
     */
    @PreAuthorize("@ss.hasPermi('basic:imageToSku:export')")
    @Log(title = "图片生成sku", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImageToSku imageToSku)
    {
        List<ImageToSku> list = imageToSkuService.selectImageToSkuList(imageToSku);
        ExcelUtil<ImageToSku> util = new ExcelUtil<ImageToSku>(ImageToSku.class);
        util.exportExcel(response, list, "图片生成sku数据");
    }

    /**
     * 获取图片生成sku详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:imageToSku:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imageToSkuService.selectImageToSkuById(id));
    }

    /**
     * 新增图片生成sku
     */
    @PreAuthorize("@ss.hasPermi('basic:imageToSku:add')")
    @Log(title = "图片生成sku", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<ImageToSku> imageToSkuList)
    {
        String username = getUsername();
        return toAjax(imageToSkuService.insertImageToSku(imageToSkuList,username));
    }

    /**
     * 修改图片生成sku
     */
    @PreAuthorize("@ss.hasPermi('basic:imageToSku:edit')")
    @Log(title = "图片生成sku", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImageToSku imageToSku)
    {
        return toAjax(imageToSkuService.updateImageToSku(imageToSku));
    }

    /**
     * 删除图片生成sku
     */
    @PreAuthorize("@ss.hasPermi('basic:imageToSku:remove')")
    @Log(title = "图片生成sku", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imageToSkuService.deleteImageToSkuByIds(ids));
    }

    @PostMapping("/ifExist")
    public AjaxResult ifExist(@RequestBody String[] imageUrl)
    {
        return success(imageToSkuService.IfExistImageToSku(imageUrl));
    }

    @PreAuthorize("@ss.hasPermi('basic:imageToSku:add')")
    @Log(title = "筛选无背景图", businessType = BusinessType.INSERT)
    @PostMapping("/insertBackgroundImage")
    public AjaxResult insertBackgroundImage(@RequestBody List<ImageToSku> imageToSkuList)
    {
        return toAjax(imageToSkuService.insertBackgroundImage(imageToSkuList));
    }
}
